#include "types.hpp"
#include "CCore.hpp"
#include <iostream>

// gccならば有効
// 読みづらいのは勘弁
#ifdef __GNUC__
extern int process_ops(CCore& game);
extern void interpret_args(int, char*[]);
#else
#define process_ops(...)
#define interpret_args(...)
#endif

position_t mkpos(int x, int y, int z)
{
	position_t p = {x,y,z};
	return p;
}

int main(int argc, char* argv[])
{
	interpret_args(argc, argv);

	// Initialize
	CCore game;

	game.Players.addPlayer(new CPlayer);
	game.Players[0]->addMob(new CMob(0, mkpos(1,2,1)));
	game.Players[0]->addMob(new CMob(2, mkpos(3,1,0)));
	game.Players.addPlayer(new CPlayer);
	game.Players[1]->addMob(new CMob(1, mkpos(5,6,2)));
//	game.Players[1]->Mobs[0]->addOperation(new Operations::CAttack(mkpos(0,1,0), 1));
//	game.Players[0]->Mobs[0]->addOperation(new Operations::CMove(mkpos(0,1,0)));
//	game.Players[0]->Mobs[1]->addOperation(new Operations::CDive());

	do
	{
		// give operations
		if(process_ops(game))
			break;

		RankedOperations ro(game.Players, game.Field);
//		RankedOperations::result_info ri;

		while(ro.executeNextOperations())
		{
			// print result
			ro.print();
#if 0
			// manually print of results
			ro.assignResults(ri);
			for(int i = 0; i < ri.size(); i++)
			{
				ri[i].first->print();
				std::cout << "Result:"
					<< ri[i].second << std::endl;
			}
#endif
		}
	}while(game.update() > -1);

	return 0;
}

